//
//  GRConfrimOrderModel.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/16.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRConfrimOrderModel.h"
#import "GRGoodTypeModel.h"
@implementation GRConfrimOrderModel


- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic{
    NSDictionary *defAddress = dic[@"defAddress"];
    _defAddressModel = [GRMyAddressEditorModel yy_modelWithDictionary:defAddress];
    NSArray * address = dic[@"address"];
    if (Array(address)) {
        NSMutableArray * addressArr = [NSMutableArray array];
        for (NSDictionary * addressDic in address) {
            [addressArr addObject:[GRMyAddressEditorModel yy_modelWithDictionary:addressDic]];
        }
        _addressArr = addressArr;
    }
    NSArray * orderArr = dic[@"orders"];
    if (Array(orderArr)) {
        NSMutableArray * orders = [NSMutableArray array];
        NSMutableArray * orderIdArr = [NSMutableArray array];
        for (NSDictionary* orderDic in orderArr) {
            [orders addObject:[GRConfirmOderGoodInfo yy_modelWithDictionary:orderDic]];
            [orderIdArr addObject:orderDic[@"id"]];
        }
        _orderIdArr = orderIdArr;
        _orders = orders;
    }
    NSArray * rateArr = dic[@"rateArray"];

    if (Array(rateArr)) {
         NSMutableArray * rateArray = [NSMutableArray array];
        
        for (NSString *rate in rateArr) {
            GRGoodStageModel * rateModel = [[GRGoodStageModel alloc]init];
            rateModel .stage = rate;
            if ([ rate integerValue]== 100) {
                rateModel .scValue = @"全款";
            }else if ([rate integerValue] == 0){
                rateModel .scValue = @"零首付";
                
            }else{
                rateModel .scValue = [NSString stringWithFormat:@"%@%%",rate];
            }
            if ([rateModel.stage integerValue] == self.rate) {
                rateModel.ifSelect = YES;
            }else{
                rateModel.ifSelect = NO;
            }
            rateModel.stageType = 1;
            [rateArray addObject:rateModel];
        }
        _rateArray = rateArray;
    }
 
    NSArray * byStagesArray = dic[@"byStagesArray"];
    if (Array(byStagesArray)) {
    NSMutableArray * stageArr = [NSMutableArray array];
    for (NSString * stage in byStagesArray) {
        GRGoodStageModel * stageModel = [[GRGoodStageModel alloc]init];
        stageModel.stage = stage;
        if ([stage integerValue] == 0) {
            stageModel.scValue = @"不分期";
        }else{
            stageModel.scValue = [NSString stringWithFormat:@"%@期",stage];
        }
        if ([stageModel.stage integerValue] == self.byStages) {
            stageModel .ifSelect = YES;
        }else{
            stageModel .ifSelect = NO;
        }
        stageModel.stageType = 2;
        [stageArr addObject:stageModel];
    }
    _byStagesArray = stageArr;
    }

    
    return YES;
}
// 如果实现了该方法，则处理过程中会忽略该列表内的所有属性
+ (NSArray *)modelPropertyBlacklist {
    return @[
             @"defAddressModel",
             @"addressArr",
             @"orders",
             @"orderIdArr",
             @"rateArray",
             @"byStagesArray"
             ];
}


@end

@implementation GRConfirmOrderGoodModel

@end

@implementation GRConfirmOderGoodInfo
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic{

    NSArray * orderArr = dic[@"orderInfos"];
    if (Array(orderArr)) {
        NSMutableArray * orders = [NSMutableArray array];
        for (NSDictionary* orderDic in orderArr) {
            [orders addObject:[GRConfirmOrderGoodModel yy_modelWithDictionary:orderDic]];
        }
        _orderInfos = orders;
    }
    
    return YES;
}
// 如果实现了该方法，则处理过程中会忽略该列表内的所有属性
+ (NSArray *)modelPropertyBlacklist {
    return @[
             @"orderInfos",
             ];
}

@end
@implementation GRInvoiceModel

@end



